<template>
  <div class="home">
    <div class="myswiper">
      <van-overlay :show="show" class-name="bgcolor">
        <div class="wrapper" @click.stop>
          <div class="block" />
        </div>
      </van-overlay>
      <van-swipe :autoplay="3000" class="myul">
        <van-swipe-item v-for="image in images" :key="image.id" class="myli">
          <router-link
            :to="{ name: 'content', query: { id: '123' } }"
          ></router-link>
          <img v-lazy="image.img" />
        </van-swipe-item>
      </van-swipe>
    </div>
    <section>
      <hello-world />
    </section>
  </div>
</template>

<script>
// @ is an alias to /src
import HelloWorld from "@/components/HelloWorld.vue";
import { get } from "@/http/request";

export default {
  name: "HomeView",
  components: {
    HelloWorld,
  },
  data() {
    return {
      activeName: "a",
      images: [
        // "https://img01.yzcdn.cn/vant/apple-1.jpg",
        // "https://img01.yzcdn.cn/vant/apple-2.jpg",
      ],
      show: true,
    };
  },
  methods: {
    async init() {
      await get("https://apis.netstart.cn/mbcomic/Banner", { params: {} }).then(
        (res) => {
          console.log(res);
          if (res.code == 0) {
            this.images = res.data;
          }
        }
      );
    },
  },
  created() {
    this.init();
  },
  watch: {
    images(newimg, oldimg) {
      if (oldimg == null) {
        this.images = [
          "https://img01.yzcdn.cn/vant/apple-1.jpg",
          "https://img01.yzcdn.cn/vant/apple-2.jpg",
        ];
      } else if (newimg) {
        this.show = false;
      }
    },
  },
};
</script>
<style lang="scss">
.home {
  width: 100%;
  // padding: 10px;
}
.bgcolor{
  background-color: #fcfbfb;
}
.wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  .block {
    width: 120px;
    height: 120px;
    background-image: url(../../assets/1441607667576727.gif);
    background-size: cover;
    background-position-x: center;
    background-color: #fff;
  }
}

// .mybg {
//   width: 100%;
//   height: 100%;
//   background-image: url(../../assets/1441607667576727.gif);
//   background-size: cover;
//   background-repeat: no-repeat;
// }
.myswiper {
  // height: 190px;
  width: 100%;
  padding: 10px;
  padding-bottom: 0;
  .myul {
    transition: all 0.5;

    .myli {
      width: 100%;
      height: 190px;
      border-radius: 10px;
      overflow: hidden;
      // background-color: #42b983;
      text-align: center;
      // line-height: 190px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 10px;
      }
    }
  }
}
</style>